<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE head PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file="/static/include/common.inc"%>
<link rel="stylesheet" href="static/admin/css/layui.css">
<link rel="stylesheet" href="static/admin/css/main.css" media="all">
<link rel="stylesheet" href="static/layui_v2.2.3/css/zbyui.css">
<script src="static/js/jquery-1.11.2.js"></script>
<script src="static/layui_v2.2.3/layui.js"></script>
</head>
<body>
	<form class="layui-form" action="">
		<input type="hidden" name="id" value="${commonProblem.id }" id="cpId">
		<div class="layui-form-item">
			<label class="layui-form-label">标题</label>
			<div class="layui-input-block">
				<input type="text" name="name" required lay-verify="required" maxlength="64"
					placeholder="请输入标题" autocomplete="off" class="layui-input" value="${commonProblem.name }">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">发布时间</label>
			<div class="layui-input-block">
				<input type="text" name="releaseTimeStr" required
					lay-verify="required" placeholder="请输入发布时间" autocomplete="off"
					class="layui-input" id="releaseTimeStr" readonly="readonly" value="${commonProblem.releaseTimeStr }">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">阅读次数</label>
			<div class="layui-input-block">
				<input type="text" name="readNum" required lay-verify="number"
					placeholder="请输入阅读次数" autocomplete="off" class="layui-input" value="${empty commonProblem.readNum?0:commonProblem.readNum }">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">类型</label>
			<div class="layui-input-block" style="z-index: 99999;">
				<select name="problemType" lay-verify="required">
					<option value=""></option>
					<c:forEach items="${cpTypes }" var="type">
						<option value="${type.code }" ${type.code==commonProblem.problemType?"selected='selected'":"" }>${type.value }</option>
					</c:forEach>
				</select>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">内容</label>
			<div class="layui-input-block">
				<input name="content" type="hidden" id="content">
				<!-- 加载编辑器的容器 -->
				<script id="container" type="text/plain">
        			${commonProblem.content}
    			</script>
    		</div>
    	</div>
		<div class="layui-form-item">
			<div class="layui-input-block" style="align-items: center;">
				<button class="layui-btn" lay-submit lay-filter="formDemo">保存</button>
				<button class="layui-btn layui-btn-primary" id="zby-closeBtn">关闭</button>
			</div>
		</div>
	</form>
	<!-- 配置文件 -->
	<script type="text/javascript" src="static/ueditor1433/ueditor.config.js"></script>
	<!-- 编辑器源码文件 -->
	<script type="text/javascript" src="static/ueditor1433/ueditor.all.min.js"></script>
	<script type="text/javascript">
	<!-- 实例化编辑器 -->
		var ue = UE.getEditor('container', {
			initialFrameWidth : 570,
			initialFrameHeight : 200,
		});
		//事件
		/* ue.addListener("contentChange",function(){
		    $("#content").val(ue.getContentTxt());
		}); */

		layui.use([ 'form', 'laydate' ], function() {
			var form = layui.form;
			var laydate = layui.laydate;
			//执行一个laydate实例
			laydate.render({
				elem : '#releaseTimeStr' //指定元素
			});
			//监听提交
			form.on('submit(formDemo)', function(data) {
				data.field.content = ue.getContentTxt();
				alert(ue.getContentTxt())
				$(".layui-btn").addClass("layui-btn-disabled")
				$.ajax({
					type : "post",
					url : "admin/commonProblem/updateCommonProblem.do",
					data : data.field,
					async: false,
					success : function(result) {
						if (result.code == 1) {
							parent.layer.msg(result.msg);
							setTimeout(closeOpt,1500);
						} else {
							parent.layer.msg(result.msg);
						}
					}
				});
				return false;
			});
		});
		function closeOpt(){
			var index=parent.layer.getFrameIndex(window.name);
			parent.layer.close(index);
			window.parent.location.reload();
		}
		$("#zby-closeBtn").bind("click",function(){
			var index=parent.layer.getFrameIndex(window.name);
			parent.layer.close(index);
		})
		
	</script>
</body>
</html>